<template>
  <div class="user-activity">
    <div class="post">
      <div class="user-block">
        <img
          class="img-circle"
          :src="'https://wpimg.wallstcn.com/57ed425a-c71e-4201-9428-68760c0537c4.jpg'+avatarPrefix"
        >
        <span class="username text-muted">{{ prescription.userInfoVO.username }}</span>
        <span class="description">年龄：{{ prescription.userInfoVO.age }}</span>
      </div>
      <!-- <p>
        上次开具的药品
      </p> -->
    </div>

    <el-form
      class="bingli"
      :model="prescription"
    >
      <el-form-item label="病因">
        <!-- <el-input
          v-model="prescription.pathogeny"
          :disabled="true"
        /> -->
        <div>
          {{ prescription.pathogeny }}
        </div>
      </el-form-item>
      <el-form-item label="服药周期">
        <el-input
          v-model="prescription.medicationTimeStart"
          class="tian"
          :disabled="true"
        />
        -----
        <el-input
          v-model="prescription.medicationTimeEnd"
          class="tian"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item label="用药">
        <el-table
          :data="prescription.prescriptionMedicineDTOList"
          style="width: 100%"
        >
          <el-table-column
            prop="name"
            label="名称"
            width="180"
          />
          <el-table-column
            prop="number"
            label="数量"
            width="180"
          />
          <el-table-column
            prop="sellingPrice"
            label="单价"
          />
          <el-table-column
            prop="allPrice"
            label="总价"
          />
        </el-table>
      </el-form-item>
      <el-form-item label="病例">
        <el-input
          v-model="prescription.remake"
          type="textarea"
          rows="10"
          :disabled="true"
        />
      </el-form-item>
      <div style="text-align:right;">
        <el-button
          type="danger"
          @click="haddleCancel"
        >取消</el-button>
        <el-button
          type="primary"
          :disabled="prescription.payment===1"
          @click="confirmMedicine"
        >修改</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
const avatarPrefix = '?imageView2/1/w/80/h/80'
const carouselPrefix = '?imageView2/2/h/440'
import { addPrescription } from '@/api/prescription'
import { mapGetters } from 'vuex'

import { dataChange, dateChange } from '@/utils/time'

const defaultPrescription = {
  pathogeny: '',
  day: '',
  type: '1',
  remake: '',
  adminId: '',
  userId: '',
  userInfoVO: {
    username: '',
    age: ''
  }
}

export default {
  props: {
    user: {
      type: Object,
      requied: true,
      default: null
    },
    prescription: {
      type: Object,
      requied: true,
      default: () => {
        return defaultPrescription
      }
    }
  },
  data() {
    return {
      carouselImages: [
        'https://wpimg.wallstcn.com/9679ffb0-9e0b-4451-9916-e21992218054.jpg'],
      avatarPrefix,
      carouselPrefix,
      dynamicTags: ['999感冒灵', '888感冒灵', '777感冒灵'],
      inputVisible: false,
      inputValue: '',
      prescriptionMedicineList: []
    }
  },
  computed: {
    ...mapGetters(['adminId'])
  },
  methods: {
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },

    showInput() {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm() {
      const inputValue = this.inputValue
      if (inputValue) {
        this.dynamicTags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    },
    haddleCancel() {
      this.$emit('cancel')
    },
    async confirmMedicine() {
      // this.prescription.adminId = this.adminId
      // this.prescription.userId = this.user.id
      // this.medicationTimeStart = new Date().getTime()
      // this.medicationTimeEnd = dateChange(this.day, false)
      // const { message } = await addPrescription(this.prescription)
      // this.$notify({
      //   title: '提交成功',
      //   dangerouslyUseHTMLString: true,
      //   message: `
      //       <div>姓名: ${this.prescription.username}</div>
      //       <div>消息: ${message}</div>
      //     `,
      //   type: 'success'
      // })
      // this.prescription = { brand_right: 0 }
      this.$router.push({
        name: 'prescriptionDetail',
        params: {
          prescriptionId: this.prescription.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.user-activity {
  .user-block {
    .username,
    .description {
      display: block;
      margin-left: 50px;
      padding: 2px 0;
    }

    .username {
      font-size: 16px;
      color: #000;
    }

    :after {
      clear: both;
    }

    .img-circle {
      border-radius: 50%;
      width: 40px;
      height: 40px;
      float: left;
    }

    span {
      font-weight: 500;
      font-size: 12px;
    }
  }

  .post {
    font-size: 14px;
    border-bottom: 1px solid #d2d6de;
    margin-bottom: 15px;
    padding-bottom: 15px;
    color: #666;

    .image {
      width: 100%;
      height: 100%;
    }

    .user-images {
      padding-top: 20px;
    }
  }

  .list-inline {
    padding-left: 0;
    margin-left: -5px;
    list-style: none;

    li {
      display: inline-block;
      padding-right: 5px;
      padding-left: 5px;
      font-size: 13px;
    }

    .link-black {
      &:hover,
      &:focus {
        color: #999;
      }
    }
  }
}
.tian {
  width: 150px;
  margin-right: 10px;
}

.box-center {
  margin: 0 auto;
  display: table;
}

.text-muted {
  color: #777;
}

.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
